package com.service;

import com.mapper.OrderMapper;
import com.mapper.User_OrderMapper;
import com.model.Order;
import com.model.User_Order;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class User_OrderService {
    @Autowired
    private User_OrderMapper user_orderMapper;

    @Autowired
    private OrderMapper orderMapper;
    
    public boolean insertUser_Order(Long UserId,Long OrderId){
        return user_orderMapper.insertUser_Order(UserId,OrderId);
    }

    public List<Order> getOrderByUserId(Long UserId){
        List<User_Order> user_orderByUserId = user_orderMapper.getUser_OrderByUserId(UserId);
        List<Order> res=new ArrayList<>();
        for(User_Order uo:user_orderByUserId){
            Order orderByOrderId = orderMapper.getOrderByOrderId(uo.getOrderid());
            res.add(orderByOrderId);
        }
        return res;
    }
}
